<template>
  <el-dialog
    append-to-body
    :close-on-click-modal="false"
    :visible.sync="dialogFormVisible"
    :before-close="close"
    :title="title"
    width="600px"
    :top="'10vh'"
  >
    <el-form ref="form" :model="form" size="small" label-width="120px">
      <el-row :gutter="20">
        <el-col :span="24">
          <el-form-item
            label="栏目名称"
            prop="name"
            :rules="[{ required: true, message: '请输入栏目名称', trigger: 'blur' }]"
            style="width: 100%"
          >
            <el-input v-model="form.name" palceholder="请输入栏目名称" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="模版" prop="data.id" :rules="{ required: true, message: '请选择模版', trigger: 'change' }">
            <el-popover
              placement="bottom-start"
              width="450"
              trigger="click"
              @show="$refs['tempSelect'].reset()"
            >
              <custom-temp ref="tempSelect" @selected="selectedTemp" />
              <el-input slot="reference" v-model="form.data.name" style="width: 450px" placeholder="点击选择模版" readonly />
            </el-popover>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item
            label="图标"
            prop="tb"
            :rules="[{ required: true, message: '请选择图标', trigger: 'change' }]"
          >
            <el-popover
              placement="bottom-start"
              width="450"
              trigger="click"
              @show="$refs['iconSelect'].reset()"
            >
              <custom-icon ref="iconSelect" @selected="selectedIcon" />
              <el-input slot="reference" v-model="form.tb" style="width: 450px;" placeholder="点击选择图标" readonly>
                <i
                  v-if="form.tb"
                  slot="prefix"
                  :class="form.tb"
                  class="el-input__icon"
                  style="height: 32px;width: 16px;"
                />
                <i v-else slot="prefix" class="el-icon-search el-input__icon" />
              </el-input>
            </el-popover>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item
            label="是否显示图标"
            prop="sfsxtb"
            :rules="[{ required: true, message: '请选择是否显示图标', trigger: 'change' }]"
          >
            <el-radio-group v-model="form.sfsxtb">
              <el-radio
                v-for="item in status"
                :key="item.id"
                :label="item.value"
              >{{ item.label }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item
            label="是否自定义"
            prop="sfzdy"
            :rules="[{ required: true, message: '请选择是否自定义', trigger: 'change' }]"
          >
            <el-radio-group v-model="form.sfzdy">
              <el-radio
                v-for="item in status"
                :key="item.id"
                :label="item.value"
              >{{ item.label }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item
            label="是否全屏"
            prop="sfdzqp"
            :rules="[{ required: true, message: '请选择是否全屏', trigger: 'change' }]"
          >
            <el-radio-group v-model="form.sfdzqp">
              <el-radio
                v-for="item in status"
                :key="item.id"
                :label="item.value"
              >{{ item.label }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item
            label="默认高度"
            prop="defaultHeight"
            :rules="[{ required: true, message: 'defaultHeight', trigger: 'blur' }]"
            style="width: 100%"
          >
            <el-input v-model="form.defaultHeight" palceholder="defaultHeight" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item
            label="字体颜色"
            prop="fontColor"
          >
            <el-color-picker v-model="form.fontColor" placeholder="请选择字体颜色" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item
            label="背景颜色"
            prop="backgroundColor"
          >
            <el-color-picker v-model="form.backgroundColor" placeholder="请选择背景颜色" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item
            label="是否显示更多"
            prop="isMore"
            :rules="{ required: true, message: '请选择是否显示更多', trigger: 'change' }"
            style="width: 100%"
          >
            <el-radio-group v-model="form.isMore">
              <el-radio
                v-for="item in status"
                :key="item.id"
                :label="item.value"
              >{{ item.label }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col v-if="form.isMore === true" :span="12">
          <el-form-item
            label="打开方式"
            prop="dkfs"
            :rules="{ required: true, message: '请选择打开方式', trigger: 'change' }"
            style="width: 100%"
          >
            <el-radio-group v-model="form.dkfs">
              <el-radio
                v-for="item in openType"
                :key="item.id"
                :label="item.value"
              >{{ item.label }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col v-if="form.isMore === true && form.dkfs === 2" :span="24">
          <el-form-item
            label="打开地址"
            prop="path"
            :rules="{ required: true, message: '请输入打开地址', trigger: 'blur' }"
            style="width: 100%"
          >
            <el-input v-model="form.path" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="text" @click="close">取消</el-button>
      <el-button :loading="loading" type="primary" @click="save('form')">确认</el-button>
    </div>
  </el-dialog>
</template>
<script>
import CustomIcon from '@/components/CustomIcon';
import CustomTemp from '@/components/TempSelect/tempAppSelect';
export default {
  name: 'ColumnAdd',
  components: { CustomIcon, CustomTemp },
  data() {
    return {
      dialogFormVisible: false,
      title: '新增栏目',
      loading: false,
      status: [
        { id: 0, value: false, label: '否' },
        { id: 1, value: true, label: '是' }
      ],
      openType: [
        { id: 0, value: 1, label: '固定模版打开' },
        { id: 1, value: 2, label: '固定地址打开' }
      ],
      form: {
        id: null,
        name: '',
        tb: null,
        sfqy: true,
        sfzdy: false,
        sfdzqp: false,
        sfsxtb: false,
        backgroundColor: '#ffffff',
        fontColor: '#222222',
        isMore: false,
        dkfs: 1,
        path: '',
        data: {
          id: null
        },
        defaultHeight: '200px'
      },
      dataList: []
    };
  },
  methods: {
    openEntity(data) {
      if (data !== null && undefined !== data && undefined !== data.name) {
        this.form = data;
      }
      this.dialogFormVisible = true;
    },
    save(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('fetch-data', this.form);
          this.close();
        }
      });
    },
    selectedIcon(data) {
      this.form.tb = data;
    },
    close() {
      this.loading = false;
      Object.assign(this.$data.form, this.$options.data.call(this).form);
      this.dialogFormVisible = false;
    },
    selectedTemp(data) {
      this.form.data = data;
    }
  }
};
</script>

<style scoped>

</style>
